package com.shenbianyun.bosskgpay.service.pay;

import com.shenbianyun.bosskgpay.constant.MerInfoConstant;
import com.shenbianyun.bosskgpay.entity.Merchant;
import com.shenbianyun.bosskgpay.entity.RequestMessage;
import com.shenbianyun.bosskgpay.entity.pay.PaymentQueryReqModel;
import com.shenbianyun.bosskgpay.utils.*;

import java.util.ArrayList;
import java.util.List;


/**
 * @Description //调试 批量付款查询 接口6002
 * 可固定业务参数
 **/

public class TestPaymentQueryServiceD {




    public static Merchant mer = new Merchant();
    public static PaymentQueryReqModel paymentQuery = new PaymentQueryReqModel();//业务参数：自由职业者签约查询参数

    public static void main(String[] args) throws Exception {

        TestPaymentQueryServiceD.runTestPaymentQueryService();


    }

    public static String runTestPaymentQueryService() throws Exception {


        /*
         * 商户id
         * */
        mer.setMerid(MerInfoConstant.MER_ID);
        /*
         * 商户私钥
         * */
        mer.setPriKey(MerInfoConstant.MER_PRIVATE_KEY);
        /*
         * 商户公钥
         * */
        mer.setPubKey(MerInfoConstant.MER_PUBLIC_KEY);
        /*
         * 商户签名
         * */
        mer.setInterKey(MerInfoConstant.INTER_KEY);


        //公共参数
        RequestMessage rm = new RequestMessage();
        //接口地址
        rm.setFunCode("6002");
        rm.setMerId(mer.getMerid());
        rm.setVersion(MerInfoConstant.API_VERSION);
        rm.setReqId(rm.getFunCode() + System.currentTimeMillis());


        //-------------------业务参数-----------------------
        //商户批次号(企业批次号\客户批次号)
        paymentQuery.setMerBatchId("batc100951765042223222259844");

        //查询数据
        List<PaymentQueryReqModel.QueryItems> list = new ArrayList<>();
        PaymentQueryReqModel.QueryItems itemsDTO = new PaymentQueryReqModel.QueryItems();
        //商户订单号(客户订单号\企业订单号)
        itemsDTO.setMerOrderId("orde100951765042223222259845");
        //平台订单号(订单流水号)
        itemsDTO.setOrderNo("1765042235471458306");
        list.add(itemsDTO);


        //reqData转json
        String reqData = JsonUtils.toJson(paymentQuery);
        //System.out.println("reqDatajson= " + reqData);

        //reqData加密
        byte[] bs = DESUtils.encrypt(reqData.getBytes(MerInfoConstant.CHARSET_UTF_8), mer.getInterKey());
        String reqDataEncrypt = Base64Utils.encodeToString(bs);
        rm.setReqData(reqDataEncrypt);
        rm.setSign(RSAUtils.sign(reqDataEncrypt, mer.getPriKey()));

        String reqStr = JsonUtils.toJson(rm);
        System.out.println("请求数据：" + reqStr);


        String resData = HttpClientHelper.sendPost(MerInfoConstant.OMS_TEST_URL, "application/json", reqStr, "POST", MerInfoConstant.CHARSET_UTF_8);
        System.out.println("响应数据：" + resData);

        //断言
        //返回信息：DES 解密
        //ResponseMessage responseMessage = JSON.parseObject(resData, ResponseMessage.class);
        ///** 2、Base64解编码 resDATA对象解密 **/
        //String respData = responseMessage.getResData();
        //byte[] base64bs = Base64Utils.decode(respData.getBytes());
        ///** 3、DES 解密 **/
        //String resultData = DESUtils.decryptToString(base64bs, MerInfoConstant.INTER_KEY);
        //responseMessage.setResData(resultData);
        //System.out.println("解密结果："+responseMessage);
        return resData;
    }


}
